import { _decorator, Component } from 'cc';
import { addP2D, KKP2D } from "@coldcloude/kakera";
const { ccclass } = _decorator;

@ccclass('MapPosition')
export class MapPosition extends Component {
    refMap:MapPosition;
    position: KKP2D;
    calculate(){
        if(this.refMap===undefined){
            return this.position;
        }
        else{
            let x = this.position.x;
            let y = this.position.y;
            let curr = this.refMap;
            while(curr!==undefined){
                const p = curr.position;
                x += p.x;
                y += p.y;
                curr = curr.refMap;
            }
        }
        let curr:MapPosition = this;
        let r:KKP2D = this.position;
        while(curr.refMap!==undefined){
            curr = curr.refMap;
            r = addP2D(r,curr.position);
        }
        return r;
    }
}
